﻿using System;

namespace Hanhud.Web
{
    public class CMessageBox
    {
        public static void Show(System.Web.UI.Page page, string message)
        {
            if (!page.ClientScript.IsClientScriptIncludeRegistered(page.GetType(), "JQuery.UI.Position"))
            {
                page.ClientScript.RegisterClientScriptInclude("JQuery.UI.Position", page.ResolveUrl("~/Scripts/jquery.ui.position.min.js"));
            }
            if (!page.ClientScript.IsClientScriptIncludeRegistered(page.GetType(), "JQuery.UI.Mouse"))
            {
                page.ClientScript.RegisterClientScriptInclude("JQuery.UI.Position", page.ResolveUrl("~/Scripts/jquery.ui.mouse.min.js"));
            }
            if (!page.ClientScript.IsClientScriptIncludeRegistered(page.GetType(), "JQuery.UI.Resizable"))
            {
                page.ClientScript.RegisterClientScriptInclude("JQuery.UI.Position", page.ResolveUrl("~/Scripts/jquery.ui.resizable.min.js"));
            }
            if (!page.ClientScript.IsClientScriptIncludeRegistered(page.GetType(), "JQuery.UI.Dialog"))
            {
                page.ClientScript.RegisterClientScriptInclude("JQuery.UI.dialog", page.ResolveUrl("~/Scripts/jquery.ui.dialog.min.js"));
            }

            page.ClientScript.RegisterHiddenField("ctrlMessage", message);

            string scriptBlock = @"
                    $(document).ready(function(){
                        var $dialog = $('<div></div>');
                        
                        $dialog.html($('#ctrlMessage').val());
                        $dialog.dialog({    
                                title: 'Thông báo',
                                modal: true,
                                buttons: {
                                    Ok: function() {
					                    $(this).dialog('close');
				                    }
                                },
                                autoOpen: true
                            });
                    });
                ";
            page.ClientScript.RegisterStartupScript(page.GetType(), "SystemMessage", scriptBlock, true);
        }
    }
}
